/*
 * Filler.java
 *
 * Created on 9 maj 2007, 18:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package pl.krakow.ae.knp.wikiboard.gui.tools.transformers;

import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import pl.krakow.ae.knp.wikiboard.gui.board.Board;
import pl.krakow.ae.knp.wikiboard.gui.board.BoardEvent;
import pl.krakow.ae.knp.wikiboard.gui.drawables.Drawable;
import pl.krakow.ae.knp.wikiboard.gui.drawables.Figure;
import pl.krakow.ae.knp.wikiboard.gui.tools.markers.Marker;

/**
 *
 * @author m
 */

public class Filler extends Marker
{
    Figure drawable, newDrawable;
    
    public BoardEvent createEvent()
    {
        return new BoardEvent(drawable, newDrawable);
    }
    
    public void mousePressed(MouseEvent event, Graphics2D g)
    {
        Iterator<Drawable> it = Board.drawablesList.iterator();
        while(it.hasNext())
        {
            Drawable d = it.next();
            if (d.contains(event.getPoint()) && (d instanceof Figure))
            {
                drawable = (Figure)d;
                newDrawable = drawable.clone();
            }
        }
        
        if (newDrawable != null)
        {
            newDrawable.fill(Board.getFgColor());
            BoardEvent e = createEvent();
            processBoardEvent(e);
        }
    }
    
    public void mouseDragged(MouseEvent event, Graphics2D g)
    {}
    
    public void mouseReleased(MouseEvent event, Graphics2D g)
    {}
    
    public Drawable getDrawable()
    {
        return drawable;
    }
    
}
